package com.jch.dm.chapter_10_strategy;

import java.util.Random;

/**
 * @author: jch
 * 策略模式 示例
 **/
public class WinningStrategy implements Strategy {

    private Random random;
    private boolean won = false;
    private Hand prevHand;

    public WinningStrategy(int seed) {
        random = new Random(seed);
    }

    /**
     * 下一次所出的手势
     *
     * @return hand
     */
    @Override
    public Hand nextHand() {
        if (!won) {
            prevHand = Hand.getHand(random.nextInt(3));
        }
        return prevHand;
    }

    /**
     * 学习
     *
     * @param win
     */
    @Override
    public void study(boolean win) {
        won = win;
    }
}
